<?php defined('IN_LK') or die('Access Denied');?>
<?php include self::admin_t('header');?>

<ul class="main_nav">
  <li><a href="?m=admin&c=admin_manage&ac=1" target="_self" <?php echo $ac == 1 ? 'class="select"' : '';?>>管理员管理</a></li>
  <li><a href="?m=admin&c=admin_manage&ac=2" target="_self" <?php echo $ac == 2 ? 'class="select"' : '';?>>添加管理员</a></li>
</ul>
<?php if($ac == 1){?>
<div class="c"></div>
<div class="table-list">
  <table width="100%" cellspacing="0">
    <thead>
      <tr>
        <th align="left" width="7%">序号</th>
        <th align="left" width="10%">用户名</th>
        <th align="left" width="10%">角色</th>
        <th align="left" width="12%">最后登录IP</th>
        <th align="left" width="15%">最后登录时间</th>
        <th align="left" width="7%">登录次数</th>
        <th align="left">E-mail</th>
        <th align="left" width="150">管理操作</th>
      </tr>
    </thead>
    <tbody>
      <?php
	  if(isset($admin_list) && $admin_list)
	  {
      	foreach($admin_list as $admin){?>
      <tr>
        <td><?php echo $admin['userid'];?></td>
        <td><?php echo $admin['username'];?></td>
        <td><?php echo $admin['rolename'];?></td>
        <td><?php echo $admin['lastloginip'];?></td>
        <td><?php echo $admin['lastlogintime'];?></td>
        <td><?php echo $admin['logintimes'];?></td>
        <td><?php echo $admin['email'];?></td>
        <td><a href="javascript:void(0);" onclick="edit(<?php echo $admin['userid'];?>, '<?php echo $admin['username'];?>')">修改</a> |
          <?php if($admin['userid'] == 1 || $_SESSION['userid'] == $admin['userid']){?>
          <span class="pointer g8">删除</span>
          <?php }else{?>
          <a href="javascript:void(0);" onclick="del(<?php echo $admin['userid'];?>, '<?php echo $admin['username'];?>')">删除</a>
          <?php }?></td>
      </tr>
      <?php }}else{?>
      <tr>
      	<td colspan="8" align="center">暂无成员</td>
      </tr>
      <?php }?>
    </tbody>
  </table>
  <?php echo $page_nav;?>
 </div>
<script typr="text/javascript">
<!--
function edit(uid, uname)
{
	window.top.art.dialog(
	{
		width:'500px',
		height:'280px',
		title : '编辑 - ' + uname,
		iframe: '?m=admin&c=admin_manage&a=admin_edit&userid=' + uid,
		id : 'edit'
	},
	function ()
	{
		var d = window.top.art.dialog({id:'edit'}).data.iframe;
		var form = d.document.getElementById('dosubmit');
		form.click();
		return false;
	},
	function ()
	{
		window.top.art.dialog({id:'edit'}).close();
	});
}
function del(uid, uname)
{
	window.top.art.dialog(
	{
		title:'删除 - ' + uname,
		content: '你确定要删除 ' + uname + ' 吗？',
		fixed:true,
		id:'del'
	},
	function ()
	{
		$.get('?m=admin&c=admin_manage&a=admin_del&userid=' + uid, function(data)
		{
			parent.main.location.reload();
		});
		
	},
	function()
	{
		window.top.art.dialog({id:'del'}).close();
	});
}
//-->
</script>
<?php }else{?>
<div class="c"></div>
<div id="login_error" class="message msg"><span class="green">添加管理员</span></div>
<form action="?m=admin&c=admin_manage&ac=2" method="post" id="myform" name="myform">
  <dl class="form_list">
    <dd><span class="w8 left">用户名</span>
      <input type="text" class="input" name="info[username]" id="username" size="30" />
    </dd>
    <dd> <span class="left w8">密码</span>
      <input type="password" class="input" name="info[password]" id="password" size="30" />
    </dd>
    <dd> <span class="left w8">确认密码</span>
      <input type="password" class="input" name="info[password2]" id="password2" size="30" />
    </dd>
    <dd> <span class="left w8">E-mail</span>
      <input type="text" class="input" name="info[email]" id="email" size="40" />
    </dd>
    <dd> <span class="left w8">所属角色</span><?php echo $s;?> </dd>
    <dd>
      <input type="submit" class="btn" name="dosubmit" id="dosubmit" value="提交" />
    </dd>
  </dl>
</form>
<script type="text/javascript">
$(function()
{
	$.formValidator.initConfig({autotip:true,formid:"myform",onerror:function(msg){}});
	$('#username').formValidator({onshow:"请输入用户名。", onfocus:"用户名应该为3-20位之间，数字字母下划线组成。"}).inputValidator({min:3,max:20,onerror:"用户名应该为3-20位之间，数字字母下划线组成。"}).regexValidator({regexp:"username",datatype:"enum",onerror:"用户名格式错误"}).ajaxValidator({
		type : "get",
		url : "",
		data :"m=admin&c=admin_manage&a=check_username_ajax",
		datatype : "html",
		async:'false',
		success : function(data){
            if( data == "1" )
			{
                return true;
			}
            else
			{
                return false;
			}
		},
		buttons: $("#dosubmit"),
		onerror : "用户名已存在",
		onwait : "请稍候..."
	});
	$("#password").formValidator({onshow:"密码应该为3-20位之间。",onfocus:"密码应该为3-20位之间。"}).inputValidator({min:3,max:20,onerror:"密码应该为3-20位之间"});
	$("#password2").formValidator({onshow:"请输入两次密码相同。",onfocus:"请输入两次密码相同。",oncorrect:"密码输入一致"}).compareValidator({desid:"password",operateor:"=",onerror:"请输入两次密码相同。"});
	$("#email").formValidator({onshow:"请输入E-mail",onfocus:"E-mail格式错误",oncorrect:"E-mail格式正确"}).regexValidator({regexp:"email",datatype:"enum",onerror:"E-mail格式错误"}).ajaxValidator({
		type : "get",
		url : "",
		data :"m=admin&c=admin_manage&a=check_eamil_add",
		datatype : "html",
		async:'false',
		success : function(data){
            if( data == "1" )
			{
                return true;
			}
            else
			{
                return false;
			}
		},
		buttons: $("#dosubmit"),
		onerror : "邮箱已经被注册了哦",
		onwait : "请稍候..."
	});
});
</script>
<?php }?>
<?php include self::admin_t('footer');?>
